-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix support for enum/bool auxiliary signals in NX Line visualization #1738
Conversation
0c5adc7
to
2ae498c
Compare
valueLabel?: string; | ||
errors?: NumArray; | ||
auxLabels?: string[]; | ||
auxValues?: NumArray[]; | ||
auxValues?: Value<Props['dataset']>[]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if it might not be clearer to introduce a new type alias here to not reference dataset
explicitely.
It seems weird since auxValues
are not stored in dataset
. It just so happens that auxiliary dataset values have the same type as the dataset values.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, wasn't sure that it was clearer. Two goals here:
- The types of
value
and of each item inauxValues
should match (if anNXdata
group has a boolean signal, then it should be allowed to have boolean auxiliaries). This requires changingauxValues?: NumArray[]
at least toArrayValue<NumericLikeType>
to match thevalue
prop. - The dtype passed to
Dataset<ArrayShape, DType>
should match the dtype passed toArrayValue<Dtype>
. In other words, I'd like to avoid the risk of the two becoming out of sync — e.g.Dataset<ArrayShape, NumericLikeType>
andArrayValue<NumericType>
. This is why I refer to the type of thedataset
prop withValue<Prop['dataset']
.
Perhaps the second goal is not critical, since TypeScript would show an error in the container if the dtype of dataset
and value
/auxValues
did not match. So should I stick with ArrayValue<NumericLikeType>
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Opening a PR to propose a normalisation of the mapped components' props.
2ae498c
to
3eba27e
Compare
assertNumericLikeNxData
was asserting forNxData<NumericType>
instead ofNxData<NumericLikeType>
... but was correctly callingassertNumericLikeType
internally! SoMappedLineVis
thought it could only receive numeric (nd)arrays (number[] | TypedArray
) when in fact, at runtime, it could receiveboolean[]
.No errors were thrown at runtime because JS automatically coerces booleans to numbers in all mathematical operations (e.g.
Math.min(false, 2) => 0
). This typing bug would have been more problematic withbigint[]
, though.I say "Fix support", because the fix still has invisible runtime implications: I now convert boolean auxiliary arrays to number arrays in
MappedLineVis
with a new hook calleduseToNumArrays
, which avoids type coercion further down the line (e.g. inuseDomains
).